package control;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import model.Aluno;
import model.Turma;
import dao.DAOAluno;
import dao.DAOTurma;

/**
 * Servlet implementation class RemoverAlunoTurmaServlet
 */
public class RemoverAlunoTurmaServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public RemoverAlunoTurmaServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String loginAluno = request.getParameter("login_al");
		int numTurma = Integer.parseInt(request.getParameter("id_tur"));
		DAOTurma daotur = new DAOTurma();
		DAOAluno daoalu = new DAOAluno();
		
		Turma t = daotur.find(numTurma);
		Aluno a = daoalu.find(loginAluno);
		
		t.removeAluno(a);
		daotur.merge(t);
		daoalu.merge(a);
		daotur.commit();
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

}
